<?xml version="1.0" encoding="utf-8"?>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:blueonionsoftware-com:bloget:runtime:data">
  <text>
		&lt;p&gt;If you read the documentation for HttpWebRequest.GetResponse() you'll see that it returns a HttpWebResponse() object. One of the members is Status that tells you the status of the server's response. Fair enough, but there's a gotcha here. If the server returns an response like 403 (Forbidden) or 500 (Server error), a &lt;strong&gt;WebException&lt;/strong&gt; is raised. This strikes me as a bit counterintuitive since the server did reply with a valid HTTP response. Fortunately there is a way out of this conundrum. A "note" in the GetResponse() documentation gives you a chance to still determine the status.&lt;/p&gt;
		&lt;blockquote&gt;
				&lt;p&gt;
						&lt;a href="http://blueonionsoftware.com/Blog/Images/WindowsLiveWriter/HttpWebRequest.GetResponseGotchas_BC87/note2.png" atomicselection="true"&gt;
								&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="10" src="http://blueonionsoftware.com/Blog/Images/WindowsLiveWriter/HttpWebRequest.GetResponseGotchas_BC87/note_thumb.png" width="10" border="0" /&gt;
						&lt;/a&gt;
						&lt;strong&gt;
								&lt;font color="#004080"&gt;Note&lt;/font&gt;
						&lt;/strong&gt;
				&lt;/p&gt;
				&lt;p&gt;If a &lt;b&gt;WebException&lt;/b&gt; is thrown, use the &lt;a href="ms-help://ms.msdnqtr.v80.en/P_System_Net_WebException_Response.htm"&gt;Response&lt;/a&gt; and &lt;a href="ms-help://ms.msdnqtr.v80.en/P_System_Net_WebException_Status.htm"&gt;Status&lt;/a&gt; properties of the exception to determine the response from the server.&lt;/p&gt;
		&lt;/blockquote&gt;
		&lt;p&gt;Personally, I think if the server gives you a valid HTTP response, even one indicating an error, it should not raise an exception. It's not that unusual to get error responses from servers. Raising these errors as exceptions introduces exception handling into what can be considered normal control flow. Generally, this is frowned upon because the situation is not "exceptional." Also, exception handling is many times slower than straight-line code which makes it a poor choice for control flow. To quote the CLR team, "Exceptions should be exceptional."&lt;/p&gt;
</text>
  <last_update>2007-07-25T02:56:23.703125Z</last_update>
  <source_title />
  <source_link />
  <comments />
  <references />
  <attachments />
</Content>